#include "resourceeffect.h"
#include "resourcemanager.h"
#include "../defines.h"

namespace gunsmith
{
CResourceEffect::CResourceEffect() : CResource(RT_EFFECT)
{
	m_pEffect = NULL;
}

CResourceEffect::~CResourceEffect()
{
	Destroy();
}

/*!	\brief		Creates and effect from the given source.
	\param		pSource	Source filename.
	\return		bool
	\remarks	
	\sa			*/
bool CResourceEffect::Create(void *pSource)
{
	const char *cpSource = (const char*)pSource;

	ID3DXBuffer *pErrorBuffer = NULL;

	HRESULT hr = D3DXCreateEffectFromFile(m_pDevice, cpSource, NULL, NULL, 0, NULL, &m_pEffect, &pErrorBuffer);

	if(pErrorBuffer)
	{
		const char* cpErrorText = (const char*)pErrorBuffer->GetBufferPointer();
		OutputDebugStr(cpErrorText);
		pErrorBuffer->Release();
	}

	return SUCCEEDED(hr);
}

/*!	\brief		Returns the effect.
	\return		ID3DXEffect* Effect.
	\remarks	
	\sa			*/
ID3DXEffect* CResourceEffect::GetEffect() const
{
	return m_pEffect;
}

/*!	\brief		Releases effect.
	\return		void
	\remarks	
	\sa			*/
void CResourceEffect::Destroy()
{
	RELEASE(m_pEffect);
}
};